package com.itheima.mall.controller;

import com.itheima.mall.pojo.HomeNewProduct;
import com.itheima.mall.service.SmsHomeNewProductService;
import com.itheima.mall.vo.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {

    @Autowired
    private SmsHomeNewProductService smsHomeNewProductService;

    /**
     * 分页查询首页新品
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult> getList(Integer pageNum,Integer pageSize,Integer productName,Integer recommendStatus){
        PageResult pageResult = smsHomeNewProductService.getList(pageNum,pageSize,productName,recommendStatus);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 添加首页新品
     */
    @PostMapping("/create")
    public ResponseEntity<String> createNew(@RequestBody List<HomeNewProduct> homeNewProductList){
        smsHomeNewProductService.createNew(homeNewProductList);
        return ResponseEntity.ok("ok");
    }

    /**
     * 批量删除首页新品
     */
    @PostMapping("/delete")
    public ResponseEntity<String> deleteNew(@RequestParam List<Long> ids){
        smsHomeNewProductService.deleteNew(ids);
        return ResponseEntity.ok("ok");
    }

    /**
     * 批量修改首页新品状态
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity<String> updateStatus(@RequestParam List<Long> ids, Integer recommendStatus){
        smsHomeNewProductService.updateStatus(ids,recommendStatus);
        return ResponseEntity.ok("ok");
    }

    /**
     * 修改首页新品排序
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity<String> updateSort(@PathVariable Long id, Integer sort){
        smsHomeNewProductService.updateSort(id,sort);
        return ResponseEntity.ok("ok");
    }
}

